package main

import (
	"C"
	"fmt"
	"github.com/go-resty/resty/v2"
	"io/ioutil"
	"net/http"
	"net/url"
)

//参考:https://www.ctolib.com/topics-136903.html
func GetRequest(uuid string) {
	//模拟一个get提交请求
	url_temp := "http://127.0.0.1:5000/leads/info_by_uuid?uuid=" + uuid
	resp, err := http.Get(url_temp)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()                //关闭连接
	body, err := ioutil.ReadAll(resp.Body) //读取body的内容
	fmt.Println(string(body))
}

func PostRequest() {
	//模拟一个post提交请求
	inter := "http://127.0.0.1:5000/leads/update_state"
	resp, err := http.PostForm(inter, url.Values{"uuid": {"W1C6D1665IYB2XCMAFQR730TFK"}, "state": {"4"}})
	if err != nil {
		panic(err)
	}
	//关闭连接
	defer resp.Body.Close()
	//读取报文中所有内容
	body, err := ioutil.ReadAll(resp.Body)
	//输出内容
	fmt.Println(string(body))
}

func isValid(s string) bool {
	n := len(s)
	if n%2 == 1 {
		return false
	}

	pairs := map[byte]byte{
		')': '(',
		']': '[',
		'}': '{',
	}
	stack := []byte{}
	for i := 0; i < n; i++ {
		if pairs[s[i]] > 0 {
			if len(stack) == 0 || stack[len(stack)-1] != pairs[s[i]] {
				return false
			}
			stack = stack[:len(stack)-1]
		} else {
			stack = append(stack, s[i])
		}
	}
	return len(stack) == 0
}

func jiujiu() {
	for i := 1; i < 10; i++ {
		for j := 1; j <= i; j++ {
			fmt.Printf("%d*%d=%d ", i, j, i*j)
		}
		fmt.Println()
	}
}

func main() {
	//var s, sep string
	//fmt.Println(len(os.Args))
	//for i := 1; i < len(os.Args); i++ {
	//	s += sep + os.Args[i]
	//	sep = " "
	//}
	//fmt.Println(s)
	//GetRequest("IVFYONT7U9Z2Q9HQGUG8F1PSX9")
	//GetRequest()
	fmt.Println(isValid("()[]{"))
	jiujiu()

	// Create a Resty Client
	client := resty.New()

	resp, err := client.R().
		SetQueryParams(map[string]string{
			"account": "sunshicheng",
		}).SetAuthToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50Ijoic3Vuc2hpY2hlbmciLCJleHAiOjE2NDU1NTE0MTgsImlkIjoiMTg1NyIsIm5hbWUiOiLlrZnkuovmiJAifQ.iNdAOAAuooDTYHtrAtIjbW3SSWYHuP3Jv5TRuYnRgi4").
		Get("https://test-openapi.qingsongchou.com/galaxy-go/crm/staff/get-permission")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(resp)

}
